<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>查找节点，增加属性</title>
	<script type="text/javascript">
		window.onload = function(){//网页加载完成执行这个函数
			//查找body节点
			var node_body = document.all.div1;
			//查找img节点
			var imgObj = node_body.firstChild;
			//增加属性
			imgObj.setAttribute("src","http://img.php.cn/upload/course/000/000/009/580ae23c4a88a881.jpg");
			imgObj.setAttribute("width","400");
			imgObj.setAttribute("border","2");
			imgObj.setAttribute("style","cursor:pointer;");
			//删除border属性
			imgObj.removeAttribute("border");

			//创建一个<img>标记
			var imgObj = document.createElement("img");
			//增加属性
			imgObj.setAttribute("src","http://img.php.cn/upload/course/000/000/009/580ae23c4a88a881.jpg");
			imgObj.setAttribute("width","300");
	    	//将创建的图片节点，挂载到某个父节点下
	    	document.body.appendChild(imgObj);

		}

	</script>
</head>
<body>
<div id="div1"><img /></div>
</body>
</html>